package mainPackage;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;

/**
 * Class made to handle most resources that are going to be used in the game. 
 * The main method makes an instance of this class before anything else.
 * 
 * Any new resource should be initiated in the constructor and should be made public
 * 
 * This makes it easy for every place in the code to know about the program variables
 * @author Nikhil
 *
 */
public class Resource {

	public Properties config = new Properties();
	public int screenHeight;
	public int screenWidth;
	public boolean isFullScreen;
	public Resource(){
		try {
			config.load(this.getClass().getClassLoader().getResourceAsStream("Config.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		screenHeight = Integer.parseInt(config.getProperty("ResHeight"));
		screenWidth = Integer.parseInt(config.getProperty("ResWidth"));
		isFullScreen = Boolean.parseBoolean(config.getProperty("Screen"));
	}
	
	@SuppressWarnings("deprecation")
	public void updateFile(int width, int height, boolean fullScreen){
			config.setProperty("ResWidth", Integer.toString(width));
			config.setProperty("ResHeight", Integer.toString(height));
			config.setProperty("Screen", Boolean.toString(fullScreen));
			File f = new File("config.properties");
			FileOutputStream fos = null;
			try {
				fos = new FileOutputStream(f);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			config.save(fos, "");
			screenHeight = height;
			screenWidth= width;
			isFullScreen = fullScreen;
		}
		
		
	}


